; (function () {
    // return
    var productExceptSelf = function (nums) {
        let len = nums.length
        let arrLeft = new Array(len).fill(1)
        let arrRight = new Array(len).fill(1)

        for (let index = 1; index < len; index++) {
            arrLeft[index] = arrLeft[index-1]*nums[index-1]
            
        }
        for (let index = len-2; index >= 0; index--) {
            arrRight[index] = arrRight[index+1]*nums[index+1]
            
        }
        let arr = []

        for (let index = 0; index < len; index++) {
            arr.push(arrLeft[index]*arrRight[index])
            
        }
        return arr
    };

    productExceptSelf([1, 2, 3, 4])
})();

